package tetris.view;

import java.awt.Color;
import java.awt.Font;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * 
 * @author lsm
 *
 */
@SuppressWarnings("serial")
public class RanklistDialog extends JDialog{
	
	private JLabel score1,score2,score3,score4,score5;
	private JLabel name1,name2,name3,name4,name5;
	private String[][] ranking;

	public RanklistDialog(List<Entry<String, String>> list) {
		ranking = new String[5][2];
		int i=0;
		for(Map.Entry<String, String> e: list) {
			String name=e.getKey();
			String  score=e.getValue(); 
			ranking[i][0]=name;
			ranking[i][1]=score;
			i++;
			if(i==5) {
				break;
			}
		}
		Font f = new Font("Serif", Font.ITALIC, 25);
		name1 = new JLabel();
		name1.setText(ranking[0][0]);
		name1.setFont(f);
		name1.setForeground(Color.yellow);
		name1.setBounds(150,270, 100, 30);
		this.add(name1);
		score1 = new JLabel();
		score1.setText(ranking[0][1]);
		score1.setFont(f);
		score1.setForeground(Color.yellow);
		score1.setBounds(280,270,100, 30);
		this.add(score1);
		
		name2 = new JLabel();
		name2.setText(ranking[1][0]);
		name2.setFont(f);
		name2.setForeground(Color.yellow);
		name2.setBounds(150,330,100, 30);
		this.add(name2);
		score2 = new JLabel(ranking[1][1]);
		score2.setFont(f);
		score2.setForeground(Color.yellow);
		score2.setBounds(280,330,100, 30);
		this.add(score2);
		
		name3 = new JLabel();
		name3.setText(ranking[2][0]);
		name3.setFont(f);
		name3.setForeground(Color.yellow);
		name3.setBounds(150, 390, 100, 30);
		this.add(name3);
		score3 = new JLabel(ranking[2][1]);
		score3.setFont(f);
		score3.setForeground(Color.yellow);
		score3.setBounds(280, 390, 100, 30);
		this.add(score3);
		
		name4 = new JLabel();
		name4.setText(ranking[3][0]);
		name4.setFont(f);
		name4.setForeground(Color.yellow);
		name4.setBounds(150, 450, 100, 30);
		this.add(name4);
		score4 = new JLabel(ranking[3][1]);
		score4.setFont(f);
		score4.setForeground(Color.yellow);
		score4.setBounds(280, 450, 100, 30);
		this.add(score4);
		name5 = new JLabel();
		name5.setText(ranking[4][0]);
		name5.setFont(f);
		name5.setForeground(Color.yellow);
		name5.setBounds(150, 510, 100, 30);
		this.add(name5); 
		score5 = new JLabel(ranking[4][1]);
		score5.setFont(f);
		score5.setForeground(Color.yellow);
		score5.setBounds(280, 510, 100, 30);
		this.add(score5);
		
		ImageIcon icon = new ImageIcon("beautify/charts.jpg");
		JLabel background = new JLabel(icon);
		background.setBounds(0, 0, icon.getIconWidth(),icon.getIconHeight());
		JPanel imagePanel = (JPanel)this.getContentPane();
		imagePanel.setOpaque(false);
		imagePanel.setLayout(null);
		this.setModal(true);
		this.setTitle("Ranking List");
		this.setLayout(null);
		this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
		this.setResizable(false);
		this.setSize(400, 600);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}
}
